<template>
    <!-- 短信登入 -->
    <div class="message">
        <h1>短信登入</h1>
        <el-form-item label="手机号" prop="captcha" class="captchaInput">
            <el-input class="phoneNumber" v-model.number="loginForm.captcha" type="text"></el-input>
            <div class="sendCaptha">发送验证码</div>
        </el-form-item>
        <el-form-item label="验证码" prop="password">
            <el-input class="messageCaptha" type="password" v-model="loginForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('loginForm')">提交</el-button>

        </el-form-item>

    </div>
</template>
<script>

//校验验证码
var validateCaptcha = (rule, value, callback) => {
    if (value) {
        callback()
    } else {
        callback('请输入验证码')
    }

};
// 校验用户名
var validateUsername = (rule, value, callback) => {
    var uPattern = /^[a-zA-Z0-9_-]{3,16}$/
    //如果校验通过 直接回调callback
    // 校验不通过 callback 中传入参数
    if (uPattern.test(value)) {
        callback()
    } else {
        callback('3-16字母数字下划线')
    }
};
// 校验密码
var validatePassword = (rule, value, callback) => {
    if (value) {
        callback()
    } else {
        callback('请输入密码')
    }
};
export default {
    data() {

        return {
            loginForm: {
                username: '',
                password: '',
                captcha: ''
            },
            rules: {
                username: [
                    { validator: validateUsername, trigger: 'blur' }
                ],
                password: [
                    { validator: validatePassword, trigger: 'blur' }
                ],
                captcha: [
                    { validator: validateCaptcha, trigger: 'blur' }
                ]
            }
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
    }
}
</script>

<style scoped lang="less">
/deep/ h1 {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

/deep/ .el-form-item__content {
    line-height: 40px;
    position: relative;
    font-size: 14px;
    display: flex;
    align-items: center;
    /* justify-content: center; */
}
/deep/ .sendCaptha {
    background-color: #FFF;
    border-radius: 4px;
    border: 1px solid #DCDFE6;
    box-sizing: border-box;
    display: inline-block;
    height: 40px;
    line-height: 40px;
    outline: 0;
    width: 200px;
    text-align: center;
    transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 0;
}
/deep/ .messageCaptha {
    width: 240px;
}

/deep/ .phoneNumber {
    width: 160px;

    .el-input__inner {
        border: 1px solid #DCDFE6;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        border-right: 0;
    }
}
// /deep/ .phoneNumber {
//     width: 200px;
// }
/deep/ .sendCaptha{
    width: 80px;
}
</style>